import { defineStore } from 'pinia'
import type { TabPaneName } from 'element-plus'

export const useSysKeepAliveStore = defineStore('sysKeepAlive', {
    state: () => {
        return {
            list: ['amis'] as string[]
        }
    },
    actions: {
        addKeepAliveName(component: string) {
            if (!this.list.includes(component)) {
                this.list.push(component)
            }
        },
        removeKeepAliveName(component: TabPaneName) {
            this.list = this.list.filter((item) => item !== component)
        },
        removeKeepAliveNames(tags: Menu.MenuOptions[]) {
            const tagNames = new Set(tags.map((item) => item.name))
            this.list = this.list.filter((item) => tagNames.has(item))
        }
    }
})
